home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
BARNET
/
FREENET
/
HOUGHTON
/
POPST124
/
!POPstar
/
c
/
status
< prev
next >
Wrap
Text File
|
1998-03-06
|
6KB
|
255 lines
/* Status in a Toolbox window
$Header: ADFS::Nisu.\044.Internet.!POPstar.RCS.status,v.c 1.1 1998/02/25 21:57:19 root Exp root $
$Log: status,v.c $
Revision 1.1 1998/02/25 21:57:19 root
Initial revision
*/
#include <stdio.h>
#include <stdlib.h>
#include "memleak.h"
#include <string.h>
#include "event.h"
#include "gadgets.h"
#include "wimplib.h"
#include "window.h"
#include "config.h"
#include "dkm.h"
#include "err.h"
#include "log.h"
#include "res.h"
#include "status.h"
#include "stopquit.h"
static ObjectId status_id = NULL_ObjectId;
static int status_config;
struct status_info {
/*ObjectId id;*/
int count; /* Number of messages */
int total; /* Bytes in current msg */
int abstotal; /* Total number of bytes */
int transferred; /* Total transferred so far */
int lasttrans; /* Total transferred up to end of last message */
};
enum {
status_GUser = 1,
status_GMsgBytes = 4,
status_GMsgCount,
status_GTotal = 7,
status_GStop = 0x10,
status_GLabel
};
static bool status_manual = false;
static bool status_close_handler(int c, ToolboxEvent *e, IdBlock *i, void *h)
{
c=c; e=e; i=i; h=h;
status_manual = false;
return true;
}
static bool status_open_handler(int c, ToolboxEvent *e, IdBlock *i, void *h)
{
c=c; e=e; i=i; h=h;
return (status_manual = true);
}
void status_init(ObjectId id)
{
status_id = id;
E(toolbox_set_client_handle(0, id, (void *) (int) stopquit_Stop));
E(event_register_toolbox_handler(-1, event_ClickStatus,
status_open_handler, 0));
E(event_register_toolbox_handler(-1, event_CloseStatus,
status_close_handler, 0));
}
static void status_open()
{
if (config_lookup_bool("BigStatus"))
{
WimpGetWindowStateBlock wstate;
BBox extent;
E(window_get_wimp_handle(0, status_id, &wstate.window_handle));
E(wimp_get_window_state(&wstate));
E(window_get_extent(0, status_id, &extent));
wstate.visible_area.xmin = wstate.visible_area.xmax -
(extent.xmax - extent.xmin);
wstate.visible_area.ymin = wstate.visible_area.ymax -
(extent.ymax - extent.ymin);
wstate.xscroll = wstate.yscroll = 0;
E(toolbox_show_object(0, status_id, Toolbox_ShowObject_FullSpec,
&wstate.visible_area, NULL_ObjectId, NULL_ComponentId));
}
else
E(toolbox_show_object(0, status_id, Toolbox_ShowObject_Default, 0,
NULL_ObjectId, NULL_ComponentId));
}
status_handle status_create()
{
status_config = config_lookup_num("AutoStatus");
if (status_config)
{
status_handle h = malloc(sizeof(struct status_info));
if (!h)
return 0;
h->transferred = h->lasttrans = 0;
if (status_config == 2)
status_open();
return h;
}
return 0;
}
void status_free(status_handle h)
{
if (status_id != NULL_ObjectId)
{
status_blank(h);
if (!status_manual)
E(toolbox_hide_object(0, status_id));
}
free(h);
}
void status_blank(status_handle h)
{
h=h;
if (status_id != NULL_ObjectId)
{
E(displayfield_set_value(0, status_id, status_GUser, ""));
E(displayfield_set_value(0, status_id, status_GMsgBytes, ""));
E(displayfield_set_value(0, status_id, status_GMsgCount, ""));
E(displayfield_set_value(0, status_id, status_GTotal, ""));
}
}
void status_set_label(status_handle h, const char *msg)
{
h=h;
if (status_id != NULL_ObjectId)
E(button_set_value(0, status_id, status_GLabel, msg));
}
void status_show_misc(status_handle h, const char *msg)
{
h=h;
if (status_id != NULL_ObjectId)
E(displayfield_set_value(0, status_id, status_GUser, msg));
}
void status_show_user(status_handle h, const char *name, const char *server)
{
h=h;
if (status_id != NULL_ObjectId)
{
char msg[100];
sprintf(msg, "%s@%s", name, server);
E(displayfield_set_value(0, status_id, status_GUser, msg));
}
}
void status_count_total(status_handle h, int n)
{
if (h)
h->count = n;
if (status_id != NULL_ObjectId)
{
char msg[16];
sprintf(msg, "0/%d", n);
E(displayfield_set_value(0, status_id, status_GMsgCount, msg));
if (n && status_config == 1)
status_open();
}
}
void status_count(status_handle h, int m)
{
if (h)
{
h->total = 0;
h->lasttrans = h->transferred;
if (status_id != NULL_ObjectId)
{
char msg[16];
sprintf(msg, "%d/%d", m, h->count);
E(displayfield_set_value(0, status_id, status_GMsgCount, msg));
}
}
/*xsyslogf(log_NAME, log_DebugInfo, "Message : %d", m);*/
}
void status_bytes_total(status_handle h, int t)
{
char msg[16] = "0/";
if (h)
h->total = t;
if (status_id != NULL_ObjectId)
{
dkm_to_str(msg + 2, t);
E(displayfield_set_value(0, status_id, status_GMsgBytes, msg));
}
/*
xsyslogf(log_NAME, log_DebugInfo, "Total bytes in message : %s (%d)", msg, t);
*/
}
void status_bytes(status_handle h, int n)
{
if (h && status_id != NULL_ObjectId)
{
char msg[16];
int len;
dkm_to_str(msg, n);
if (h->total)
{
len = strlen(msg);
msg[len] = '/';
dkm_to_str(msg + len + 1, h->total);
}
E(displayfield_set_value(0, status_id, status_GMsgBytes, msg));
dkm_to_str(msg, h->transferred = h->lasttrans + n);
len = strlen(msg);
msg[len] = '/';
dkm_to_str(msg + len + 1, h->abstotal);
E(displayfield_set_value(0, status_id, status_GTotal, msg));
}
}
void status_total_total(status_handle h, int n)
{
if (h)
h->abstotal = n;
if (status_id != NULL_ObjectId)
{
char msg[16];
dkm_to_str(msg, n);
E(displayfield_set_value(0, status_id, status_GTotal, msg));
}
/*xsyslogf(log_NAME, log_DebugInfo, "Total bytes in maildrop : %d", n);*/
}